<template>
	<view class="message">
		<view class="com_name">
			<image class="img" :src="serviceDetail.coverImg[0]"></image>
			<view class="xinxi">
				<view class="tit">
					<view class="cu" v-if="serviceDetail.activityFlag == 1">促</view>
					<text>{{serviceDetail.title}}</text>
				</view>
				<view class="price">￥{{serviceDetail.price}}</view>
			</view>
		</view>
		<!--  -->
		<view class="empty">

		</view>
		<!--  -->
		<view class="box">
			<view class="personName">
				<text>姓名</text>
				<input type="text" placeholder="请输入姓名" v-model="message.userName">
			</view>
			<view class="personName">
				<text>联系方式</text>
				<input type="text" placeholder="请输入联系方式" v-model="message.contactNumber">
			</view>
			<view class="personName" v-if="serviceDetail.type == 1">
				<text>咨询内容</text>
			</view>
			<textarea v-if="serviceDetail.type == 1" value="" placeholder="请输入想要咨询的内容" class="textarea"
				v-model="message.content" />
		</view>
		<view class="submit">
			<button @click="submit">提交</button>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				serviceDetail: {
					coverImg: [],
					price: '',
					title: '',
					activityFlag: '',
					serviceId: '',
					type: ''
				},
				message: {
					userName: '',
					contactNumber: '',
					content: ''
				}
			}
		},
		onLoad(op) {
			let data = JSON.parse(decodeURIComponent(op.item))
			this.serviceDetail.coverImg = data.coverImg
			this.serviceDetail.price = data.price
			this.serviceDetail.title = data.title
			this.serviceDetail.activityFlag = data.activityFlag
			this.serviceDetail.serviceId = data.serviceId
			this.serviceDetail.type = op.type
		},
		methods: {
			//提交
			submit() {
				let userInfo = uni.getStorageSync('userInfo')
				let that = this
				if (that.serviceDetail.type == 1) {
					uni.request({
						url: that.$serverUrl + 'ftLeaveMessage',
						method: 'POST',
						data: {
							"serviceId": that.serviceDetail.serviceId,
							"contactNumber": that.message.contactNumber,
							"content": that.message.content,
							"userName": that.message.userName,
							"type": that.serviceDetail.type,
							"userId": userInfo.id
						},
						success: (res) => {
							uni.showToast({
								title: '提交成功',
								icon: 'none'
							})
							this.addServiceAdvisoryNumber(that.serviceDetail.serviceId)
						},
						fail: (e) => {
							uni.showToast({
								title: '提交失败',
								icon: 'none'
							})
						}
					})
				} else {
					uni.request({
						url: that.$serverUrl + 'ftLeaveMessage',
						method: 'POST',
						data: {
							"serviceId": that.serviceDetail.serviceId,
							"contactNumber": that.message.contactNumber,
							"userName": that.message.userName,
							"type": that.serviceDetail.type,
							"userId": userInfo.id
						},
						success: (res) => {
							uni.showToast({
								title: '提交成功',
								icon: 'none'
							})
						},
						fail: (e) => {
							uni.showToast({
								title: '提交失败',
								icon: 'none'
							})
						}
					})
				}
			},
			//增加咨询量
			addServiceAdvisoryNumber(serviceId) {
				uni.request({
					url: this.$serverUrl + 'ftService/addServiceAdvisoryNumber/' + serviceId,
					success: (res) => {

					}
				})
			}
		}
	}
</script>

<style>
	.message {

		height: 100%;
		overflow: hidden;
	}

	.com_name {

		margin: 36upx;
		display: flex;
		align-items: center;
	}

	.img {
		width: 212upx;
		height: 142upx;
		background-color: #4CD964;
		border-radius: 10upx;
	}

	.cu {
		width: 50upx;
		height: 50upx;
		background-color: #f87935;
		color: #FFFFFF;
		text-align: center;
		line-height: 50upx;
		border-radius: 5upx;
		margin-right: 15upx;
		padding: 5upx;
	}

	.xinxi {
		margin-left: 26upx;
	}

	.tit {
		display: flex;
		align-items: flex-start;
		font-size: 30upx;
	}

	.cu {
		margin-right: 10upx;
	}

	.price {
		margin-top: 30upx;
		color: #DE3232;
		font-weight: bold;
	}

	/* empty */
	.empty {
		height: 18upx;
		background-color: #F5F5F5;
	}

	.box {
		margin: 0 36upx;

	}

	.personName {
		height: 124upx;
		display: flex;
		align-items: center;
	}

	.personName text {
		width: 180upx;
		font-size: 32upx;
	}

	.textarea {
		width: 100%;
		height: 282upx;
		background-color: #F5F5F5;
	}

	/* 添加按钮 */
	.submit {
		width: 100%;
		height: 88upx;
		position: fixed;
		bottom: 40upx;

	}

	.submit button {
		margin: 0upx 36upx;
		background-color: #00B2CA;
		color: #FFFFFF;
	}
</style>
